package com.example.Service.Iml;

import com.example.Mapper.EyeMapper;
import com.example.Service.EyeService;
import com.example.staticlei.eye;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalTime;
import java.util.Arrays;

@Service
public class EyeServiceIml implements EyeService {
    @Autowired
    private EyeMapper eyeMapper;

    @Override
    public eye eyeMessage(String time) {
        String timesis0 ="子时";
        if (time.length() == 4 || time.length() ==6) {
            String hourtime = time.substring(0, 2);
            int times = Integer.parseInt(hourtime);
            if (times != 0) {
                String timeName = ReturnAncientTime(times);
                return eyeMapper.eye(timeName);
            } else {
               return eyeMapper.eye(timesis0);
            }
        }else if (time.length()==3 || time.length() == 5){
            String time1 = time.substring(0, 1);
            String time2= "0"+time1;
            int times = Integer.parseInt(time2);
            if (times != 0) {
                String timeName = ReturnAncientTime(times);
                return eyeMapper.eye(timeName);
            } else {
                return eyeMapper.eye(timesis0);
            }
        }else {
            return new eye(0, "有误", "有误", "有误", "有误");
        }
    }

    public static String ReturnAncientTime(int hour) {
        String ancientTime;
        if (hour >= 23 || hour < 1) {
            ancientTime = "子时";
        } else if (hour >= 1 && hour < 3) {
            ancientTime = "丑时";
        } else if (hour >= 3 && hour < 5) {
            ancientTime = "寅时";
        } else if (hour >= 5 && hour < 7) {
            ancientTime = "卯时";
        } else if (hour >= 7 && hour < 9) {
            ancientTime = "辰时";
        } else if (hour >= 9 && hour < 11) {
            ancientTime = "巳时";
        } else if (hour >= 11 && hour < 13) {
            ancientTime = "午时";
        } else if (hour >= 13 && hour < 15) {
            ancientTime = "未时";
        } else if (hour >= 15 && hour < 17) {
            ancientTime = "申时";
        } else if (hour >= 17 && hour < 19) {
            ancientTime = "酉时";
        } else if (hour >= 19 && hour < 21) {
            ancientTime = "戌时";
        } else {
            ancientTime = "亥时";
        }

        return ancientTime;
    }
}
